package happy.study.clique.module.study.design.strategy.code;

import happy.study.clique.module.study.design.strategy.code.model.OneStrategy;
import happy.study.clique.module.study.design.strategy.code.model.TagEnum;
import happy.study.clique.module.study.design.strategy.code.model.ThreeStrategy;
import happy.study.clique.module.study.design.strategy.code.model.TwoStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fsq
 * @date 2021/11/11 18:01
 **/
public class StrategyMapper {

    private StrategyMapper() {
    }

    private static Map<TagEnum, StrategyInterface> strategyMap = new HashMap<>();

    static {
        strategyMap.put(TagEnum.ONE_STRATEGY, new OneStrategy());
        strategyMap.put(TagEnum.TWO_STRATEGY, new TwoStrategy());
        strategyMap.put(TagEnum.THREE_STRATEGY, new ThreeStrategy());
    }

    public static StrategyInterface getStrategy(TagEnum tag) {

        StrategyInterface strategy = strategyMap.get(tag);
        if (strategy == null) {
            throw new RuntimeException("策略不匹配！请检查是否已实现。");
        }
        return strategy;
    }
}
